package com.holy.sh.module_base_mvp.utils;

import android.os.CountDownTimer;
import android.widget.TextView;

/**
 * Created by victorhhl on 2016/12/14.
 */
public class CountDownTime extends CountDownTimer {

    private TextView showTime;

    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    public CountDownTime(long millisInFuture, long countDownInterval, TextView textView) {
        super(millisInFuture, countDownInterval);
        showTime = textView;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (null != showTime) {
            showTime.setClickable(false);
            showTime.setEnabled(false);
            showTime.setText("剩余" + millisUntilFinished / 1000 + "秒");
        }
    }

    @Override
    public void onFinish() {
        if (null != showTime) {
            showTime.setText("获取验证码");
            showTime.setClickable(true);
            showTime.setEnabled(true);
        }
    }
}
